{include file='header'/}
<style>
    .layui-tab-item{margin-bottom:15px;}
</style>
<body>
<div class="weadmin-body">
    <form class="layui-form" action="javascript:;" onsubmit="return dosub(this)" method="post">
        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">基本选项</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="we-red">*</span>父级分类
                        </label>
                        <div class="layui-input-block" style="width:343px">
                            <select name="pid">
                                <option value="0">做为一级栏目</option>
                                {$select_cate|raw}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="we-red">*</span>栏目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" name="name" value="" lay-verify="required" autocomplete="off" class="layui-input xv_hanzi" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">链接地址</label>
                        <div class="layui-input-block">
                            <input type="text" id="pc_link" name="pc_link" lay-verify="required|siteUrl" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">栏目图片</label>
                        <div class="layui-input-inline" style="width: 45%">
                            <input type="text" name="image"  value=""  onmouseover="hui_img_preview('image',this.value)" onmouseout="layer.closeAll();" id="image" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width: 120px">
                            <button type="button" class="layui-btn" id="image1" ><i class="layui-icon">&#xe67c;</i>上传图片</button>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-inline">
                            <input type="number" id="weigh" name="weigh" autocomplete="off" class="layui-input" value="0" placeholder="请输入数字">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="status" class="layui-form-label">是否显示</label>
                        <div class="layui-input-inline" id="status">
                            <input type="radio" name="status" value="1" title="显示" checked>
                            <input type="radio" name="status" value="0" title="不显示" >
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <input type="hidden" name="dosubmit" value="1">
            <input type="hidden" name="type" value="{$type}">
            <button class="layui-btn"  lay-submit=""type="submit"   value="1" name="dosubmit">确定</button>
        </div>
    </form>
</div>

{include file='footer'/}
</body>
</html>
<script>
    layui.use(['form','upload'], function() {
        var form = layui.form,
            upload = layui.upload;
        form.render();
        form.verify({
            siteUrl:[
                /^http(.+)$/
                ,'链接网址格式为：http://www.baidu.com！'
            ]
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#image1'
            , url: "{:url('upload/index')}"
            ,field:"Filedata"
            ,done: function(res){
                if(res.status==1){
                    $("#image").val(res.src);
                }
            }

        })
    });
    function dosub(obj) {
        var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[-/]){0,29}$/;
        if(!reg.test($("input[name='nickname']").val())){
            layer.msg('栏目目录只能以英文字符开始，且不能包含特殊字符！',{icon:2});
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '{:url('add')}',
            data: $(obj).serialize(),
            dataType: "json",
            success: function (res) {
                if(res.status == 1){
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 200
                    }, function(){
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.msg);
                }
            }
        });
        return false;
    }
</script>